import java.util.*;
public class Spoj01{

public class Chain{

int size;
ChainNode firstNode;

public Chain(){
	firstNode=new ChainNode();
}
public void add(String name,int total)
{
	if(size==0) 
	{
		firstNode.name=name;
		firstNode.total=total;
		size++;
	}
	else 
	{
	ChainNode traverse=firstNode;
	
	for(int i=0;i<size-1;i++){
		traverse =traverse.next;
	}
	traverse.next=new ChainNode(name, total);
	size++;
	}
	}

public String toString(ChainNode traverse){
	
	String str="";
	str=traverse.name+" "+traverse.total;
	return str;
	
}


}
public class ChainNode{
	
 ChainNode next;
 String name;
 int total;
 
 public ChainNode(){}
 
public ChainNode(String name,int total){
	 
	 this.name =name;
	 this.total=total;
 }
 
}


public static void main(String args[]){
	
Spoj01 x=new Spoj01();
Chain y = x.new Chain();

int total=0;
String name="";
int counter0=0;

Scanner scanner = new Scanner(System.in);
int numOfAcc=scanner.nextInt();
int numOfPro=scanner.nextInt();

while (numOfAcc>0){
	scanner.nextLine();
	name = scanner.next();
	
	for (int i=numOfPro;i>0;i--){
		
		if(scanner.nextInt()==1)counter0++;
		else;
	}
    y.add(name,counter0);
    numOfAcc--;
    counter0=0;
}
ChainNode traverse=y.firstNode;
for (int i=0; i<y.size;i++){
	System.out.println(y.toString(traverse));
	traverse=traverse.next;
}

}

}	
